package com.yiren.manager.ctrl.test;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yiren.core.repository.utils.QueryResult;
import com.yiren.core.utils.HTTPResult;
import com.yiren.entity.YrTestResultItem;
import com.yiren.manager.ctrl.GenericController;
import com.yiren.manager.form.test.YrTestResultItemForm;
import com.yiren.manager.service.iface.test.YrTestResultItemService;
import com.yiren.manager.utils.ObjectUtils;

@RequestMapping("testResultItem")
@Controller
public class YrTestResultItemController extends GenericController<YrTestResultItemForm, YrTestResultItem>{
	
	@Autowired
	private YrTestResultItemService selfService;
	
	
	@RequestMapping("find")
	@ResponseBody
	public HTTPResult<YrTestResultItemForm> find(String searchVal) throws Exception{
		HTTPResult<YrTestResultItemForm> result = new HTTPResult<YrTestResultItemForm>();
		String sqlWhere = "test_topice_id=?1";
		QueryResult<YrTestResultItem> qr = selfService.find(YrTestResultItem.class, sqlWhere, new Object[]{searchVal});
		List<YrTestResultItemForm> formList = new ArrayList<YrTestResultItemForm>();
		for(YrTestResultItem testResultItem : qr.getResultList()){
			formList.add(toForm(testResultItem));
		}
		result.setData(formList);
		return result;
	}
	
	@Override
	public YrTestResultItemForm toForm(YrTestResultItem e) throws Exception {
		YrTestResultItemForm form = ObjectUtils.objectToObject(e, YrTestResultItemForm.class);
		return form;
	}

	@Override
	public YrTestResultItem toEntity(YrTestResultItemForm f) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
